package org.example.util;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.util.UUID;

@Component
public class FileUtil {

    @Value("${web.upload-path}")
    private String uploadFilePath;

    @Value("${web.loading-path}")
    private String loadPath;
    /**
     *处理文件上传
     **/
    public String uploadFile(MultipartFile file)throws Exception {
        String originalFilename = file.getOriginalFilename();
        String exName = originalFilename.substring(originalFilename.lastIndexOf("."));
        String fileName = UUID.randomUUID().toString() + exName;


        String filePath = uploadFilePath + fileName;
        System.out.println(filePath);
        File uploadFile = new File(filePath);
        file.transferTo(uploadFile);
        filePath = loadPath + fileName;
        return filePath;
    }
}
